using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;

namespace CKS.SharePoint.Workbook.Community {
    public partial class LeaveCommunityControl : System.Web.UI.UserControl {
        protected void Page_Load(object sender, EventArgs e) {

        }

        protected void leaveButton_Click(object sender, EventArgs e) {
            SPWeb site = SPContext.Current.Web;

            site.Users.RemoveByID(site.CurrentUser.ID);

            RedirectUser();
        }

        protected void cancelButton_Click(object sender, EventArgs e) {
            RedirectUser();
        }

        private void RedirectUser() {
            if (!string.IsNullOrEmpty(Request["Source"])) {
                Response.Redirect(Request["Source"]);
            }

            // Redirect to the root of the site if no source specified.
            SPWeb site = SPContext.Current.Web;
            Response.Redirect(site.ServerRelativeUrl);
        }
    }
}